package logic.weapons.projectileWeapons.heatSeeker;

import com.jme.math.Vector3f;
import com.jme.scene.Node;

import logic.nodes.TeamNode;
import logic.ships.hunter.Hunter;
import logic.weapons.WeaponFire;
import logic.weapons.WeaponType;
import logic.weapons.projectileWeapons.Projectile;
import logic.weapons.projectileWeapons.ProjectileWeapon;
import main.InitGame;

public class HeatSeekerWeapon extends ProjectileWeapon {
	
	private static final long serialVersionUID = 1L;
	
	private Hunter hunter;
	
	public HeatSeekerWeapon(Node model, String path, String title, HeatSeekerProperties properties, Hunter hunter) {
		super(model, path, title, properties, hunter);
		this.hunter = hunter;
	}
	
	@Override
	protected Projectile createProjectile(Vector3f direction, Node projectileModel, Vector3f startLoc, boolean dummy) {
		TeamNode target = hunter.getPilot().getCurrentTarget();
		return new HeatSeeker(ship, projectileModel, target, startLoc, direction, getHeatSeekerProperties(), this, dummy);
	}
	
	@Override
	public WeaponFire fire(Vector3f direction, boolean dummy) {
		WeaponFire fire = super.fire(direction, dummy);
		if(InitGame.get().isServer() && fire != null) {
			assert(!dummy);
			HeatSeeker hs = (HeatSeeker)fire;
			InitGame.get().getServerState().registerSyncObject(hs);
		}
		return fire;
	}
	
	public HeatSeekerProperties getHeatSeekerProperties() { return (HeatSeekerProperties)properties; }
	
	@Override
	public WeaponType getWeaponType() { return WeaponType.HeatSeeker; }
}